home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / pinfocom_3_0.lha / Source / jump.c < prev    next >
C/C++ Source or Header  |  1992-10-22  |  3KB  |  132 lines

  1. /* jump.c
  2.  *
  3.  *  ``pinfocom'' -- a portable Infocom Inc. data file interpreter.
  4.  *  Copyright (C) 1987-1992  InfoTaskForce
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; see the file COPYING.  If not, write to the
  18.  *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * $Header: RCS/jump.c,v 3.0 1992/10/21 16:56:19 pds Stab $
  23.  */
  24.  
  25. #include    "infocom.h"
  26.  
  27. void
  28. gosub A2(word, num, const word *, param)
  29. {
  30.     extern word     pc_offset;
  31.     extern word     pc_page;
  32.     extern word     *stack_base;
  33.     extern word     *stack_var_ptr;
  34.     extern word     *stack;
  35.  
  36.     /*
  37.      * The first param is the address to gosub to
  38.      */
  39.     if (param[0] == 0)
  40.         store(param[0]);
  41.     else
  42.     {
  43.         const word *pp;
  44.         byte vars;
  45.  
  46.         *(--stack) = pc_page;
  47.         *(--stack) = pc_offset;
  48.  
  49.         /* Push offset of old stack_var_ptr from stack_base onto stack */
  50.  
  51.         *(--stack) = stack_base - stack_var_ptr;
  52.  
  53.         pc_page = param[0] >> 8;
  54.         pc_offset = (param[0] & 0xFF) << 1;
  55.         fix_pc();
  56.  
  57.         /*
  58.             The value of the current stack pointer is the
  59.             new value of stack_var_ptr.
  60.         */
  61.  
  62.         stack_var_ptr = stack;
  63.         --stack_var_ptr;
  64.  
  65.         /*
  66.          * Global variables 1 to 15 are Local variables, which
  67.          * reside on the stack (and so are local to each procedure).
  68.          *
  69.          * Get number of local variables to push onto the stack.
  70.          * param[1] through param[num-1], if defined, are the first
  71.          * local variables. There are also bytes reserved after the
  72.          * gosub opcode in the calling procedure to initialise all
  73.          * local variables - including the first 3 local variables
  74.          * (and so are ignored).
  75.          */
  76.         NEXT_BYTE(vars);
  77.  
  78.         for (--num, pp=¶m[1]; (num > 0) && (vars > 0); ++pp, --num, --vars)
  79.         {
  80.             next_word();
  81.             *(--stack) = *pp;
  82.         }
  83.  
  84.         while (vars-- > 0)
  85.             *(--stack) = next_word();
  86.     }
  87. }
  88.  
  89. void
  90. rtn A1(word, value)
  91. {
  92.     extern word     pc_offset;
  93.     extern word     pc_page;
  94.     extern word     *stack_base;
  95.     extern word     *stack_var_ptr;
  96.     extern word     *stack;
  97.  
  98.     stack = stack_var_ptr;
  99.     ++stack;
  100.     stack_var_ptr = stack_base - *stack++;
  101.     pc_offset = *stack++;
  102.     pc_page = *stack++;
  103.     fix_pc();
  104.  
  105.     store(value);
  106. }
  107.  
  108. void
  109. jump A1(word, offset)
  110. {
  111.     extern word     pc_offset;
  112.  
  113.     pc_offset += offset - 2;
  114.     fix_pc();
  115. }
  116.  
  117. void
  118. rts()
  119. {
  120.     extern word     *stack;
  121.  
  122.     rtn(*stack++);
  123. }
  124.  
  125. void
  126. pop_stack()
  127. {
  128.     extern word     *stack;
  129.  
  130.     ++stack;
  131. }
  132.